#coding=utf-8
from PublicTool.ViewHelper import ViewHelper
import models
import forms
from PublicTool import HttpWrite
__author__ = 'czq'
class ReportView(ViewHelper):
    def __init__(self):
        self.moduleName='Help'
        self.typeName='report'
    def get_model(self):
        return models.Report
    def add_get_form(self,request):
        return forms.ReportForm

    #def add_get_dict(self,request):
    #    url=request.GET.get('url','')

    def add_save_prev(self,request,instance,change):
        if not change:
            report=models.Report.objects.filter(url=instance.url)[:1]
            if report:
                return HttpWrite.infoSuccess(request,u'感谢你的反馈，已经有人举报')
            else:
                instance.addUser=request.user
        return True
    def add_response_succeed(self,request,dict,instance):
        return HttpWrite.infoSuccess(request,u'举报成功，请等待管理员审核！')
    def add(self,request,id):
        return super(ReportView,self).add(request,id)